package org.micode.common.helper;

import org.apache.commons.lang3.ThreadUtils;

import java.util.concurrent.atomic.AtomicInteger;

public class ThreadHelper {

    private static final AtomicInteger threadNumber = new AtomicInteger(1);

    public static int getNextThreadNumber() {
        int ret = threadNumber.getAndIncrement();
        if (ret > 100000) {
            threadNumber.set(0);
        }
        return ret;
    }

    public static void execute(Runnable runnable) {
        execAsync(runnable, false);
    }

    public static Runnable execAsync(Runnable runnable, boolean isDaemon) {
        Thread thread = new Thread(runnable);
        thread.setDaemon(isDaemon);
        thread.start();
        return runnable;
    }

}
